#include <stdio.h>
#include <string.h>
#include "driver/ledc.h"
#include "driver/gpio.h"
#include "my_pwm.h"
#include "led.h"


void my_ledc_pwm_init(void)
{
    ledc_timer_config_t ledc_timer_str;
    ledc_timer_str.duty_resolution = LEDC_TIMER_13_BIT;//设置pwm占空比分辨率
    ledc_timer_str.freq_hz = 5000; //频率
    ledc_timer_str.speed_mode=LEDC_HIGH_SPEED_MODE;
    ledc_timer_str.timer_num = LEDC_TIMER_0; // 选择定时器
    ledc_timer_str.clk_cfg=LEDC_AUTO_CLK;
    ledc_timer_config(&ledc_timer_str); 

    ledc_channel_config_t   ledc_channel_str;
    ledc_channel_str.gpio_num=led_gpio;//IO映射
    ledc_channel_str.speed_mode=LEDC_HIGH_SPEED_MODE;//PWM速度
    ledc_channel_str.channel=LEDC_CHANNEL_0;//哪个通道
    ledc_channel_str.intr_type=0;//中断失能
    ledc_channel_str.timer_sel=LEDC_TIMER_0;//选择定时器0
    ledc_channel_str.duty=0;                  /*!< LEDC channel duty, the range of duty setting is [0, (2*duty_resolution)] */
    ledc_channel_config(&ledc_channel_str);

    ledc_fade_func_install(0);//安装LEDC渐变功能
}
